#ifndef NJF_RASTER_UTIL_H
#define NJF_RASTER_UTIL_H

#if defined(__cplusplus)
    #define EXTERNC extern "C"
#else
    #define EXTERNC extern
#endif /* C++ */

/* disable cranky Visual C warnings */
#ifdef _MSC_VER
    #pragma warning( disable : 4100 ) /* unused formal arguments */
    #pragma warning( disable : 4244 4242 ) /* possible loss of data */
    #pragma warning( disable : 4204 ) /* nonstandard extension: non-constant aggregate initializer */
    #pragma warning( disable : 4201 ) /* nonstandard extension: nameless struct or union */
    #pragma warning( disable : 4820 ) /* added padding to struct */
    #pragma warning( disable : 4305 ) /* truncation from double to float */
    #pragma warning( disable : 4710 ) /* function not inlined */
    #pragma warning( disable : 4711 ) /* function selected for automatic inlining */
#endif

#ifdef __GNUC__
    #define BEST_INLINE static __attribute__((gnu_inline)) inline
    #define ALWAYS_INLINE static __attribute((gnu_inline,always_inline)) inline
#elif defined(_MSC_VER)
    #define BEST_INLINE __inline
    #define ALWAYS_INLINE __forceinline
#else
    #define BEST_INLINE static
#endif

ALWAYS_INLINE int ICLAMP(int a, int mn, int mx)
{
    if(a > mx)
        a = mx;
    if(a < mn)
        a = mn;
    return a;
}

ALWAYS_INLINE int IMAX(int a, int b)
{
    if(a > b)
        return a;
    return b;
}
ALWAYS_INLINE int IMIN(int a, int b)
{
    if(a > b)
        return b;
    return a;
}
ALWAYS_INLINE int IABS(int a)
{
    if(a > 0)
        return a;
    return -a;
}

#ifdef __GNUC__
    #define GCC_ALIGNED(val) __attribute__((aligned((val))))
#else
    #define GCC_ALIGNED(val)
#endif
#ifdef _MSC_VER
    #define MSC_ALIGNED(val) __declspec(align(val))
#else
    #define MSC_ALIGNED(val)
#endif

#endif /* NJF_RASTER_UTIL_H */
